package gameObject;


import java.awt.event.KeyEvent;

import main.Core;
import main.Input;
import action.DefinedMovement;
import action.PeriodicAction;
import content.Content;
import data.Float2;
import data.ImageSprite;

/**
 * 
 * @author Ygor
 * 
 */
public class AdvancedArrow extends ImageSprite {

	private Float2[] positions;
	private float speed;
	private int position;
	private DefinedMovement mov;
	private PeriodicAction periodMov;
	
	public AdvancedArrow(Float2[] positions, int w, int h, Core c) {
		super(Content.loadImage("MENU_Arrow"), 0, 0, w, h, c);
		if (null != positions)
		{
			this.setX((int)positions[0].getF1());
			this.setY((int)positions[0].getF2());
		}
		periodMov = new PeriodicAction();
		periodMov.start(6.6f, (float)this.getX(), 1f);
		position = 0;
		speed = 0.2f;
		
		mov = new DefinedMovement(speed, positions);
	}
	
	@Override
	public void Update (float elapsedTime)
	{
		super.Update(elapsedTime);
		if (mov.isMoving())
		{
			Float2 pos = mov.Update(elapsedTime);
			if (null != pos)
			{
				this.setX((int)pos.getF1());
				this.setY((int)pos.getF2());
				periodMov.start(6.6f, (float)this.getX(), 1f);
			}
		}
		else
		{
			this.setX((int)(float)(periodMov.link((float)this.getX(), (float)elapsedTime)));
		}
	}
	
	public void OnKeyPress(KeyEvent keyPressed)
	{
		if (Input.up(keyPressed))
		{
			mov.MoveBack();
		}
		if (Input.down(keyPressed))
		{
			mov.MoveFoward();
		}
	}

	/**
	 * @return the positions
	 */
	public Float2[] getPositions() {
		return positions;
	}

	/**
	 * @param positions the positions to set
	 */
	public void setPositions(Float2[] positions) {
		this.positions = positions;
	}

	/**
	 * @return the speed
	 */
	public float getSpeed() {
		return speed;
	}

	/**
	 * @param speed the speed to set
	 */
	public void setSpeed(float speed) {
		this.speed = speed;
	}

	/**
	 * @return the position
	 */
	public int getPosition() {
		return position;
	}

	/**
	 * @param position the position to set
	 */
	public void setPosition(int position) {
		this.position = position;
	}

	/**
	 * @return the mov
	 */
	public DefinedMovement getMov() {
		return mov;
	}

	/**
	 * @param mov the mov to set
	 */
	public void setMov(DefinedMovement mov) {
		this.mov = mov;
	}
	
	public String toString(){
		return "Advanced Arrow "+ getLocation()+" ;; " + super.toString();
	}
}
